﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using JSC.Portal.Web.App.Modules.Articles.Services;
using JSC.Portal.Web.Controllers;
using System.Web.Mvc;
using JSC.Portal.Entities;
using JSC.Core;
using JSC.Core.Data;
using JSC.Portal.Module;
using JSC.Portal.Web.App.Modules.Articles.Entities;
using JSC.Portal.Web.Models;

namespace JSC.Portal.Web.App.Modules.Articles
{
    public class ArticlesController : ModuleServicedController<ArticleModule, IArticleService>
    {
        public ActionResult List(int sectionId)
        {
            LoadModule(sectionId);
            IList<Article> articles = Service.GetArticles(sectionId, Module.SortBy, Module.SortDirection);
            EditViewDTO<IList<Article>> data = new EditViewDTO<IList<Article>>(Section, articles); 
            return PartialView("ArticleList", data);          
        }

        public ActionResult Add(int sectionId)
        {
            LoadModule(sectionId);
            Article a = new Article();
            a.Section = Section;
            return PartialView("ArticleEditView", a);
        }

        public ActionResult SaveOrUpdate(int sectionId)
        {
            LoadModule(sectionId);
            return null;
        }

        protected override Dictionary<string, string> GetDefaultModuleActions()
        {
            Dictionary<string, string> result = base.GetDefaultModuleActions();
            result.Add(JSC.Portal.Web.App.Resources.Msg.AddArticle,
                Url.Action("Add", ModuleControllerNames.ARTICLES_CONTROLLER, new { sectionid = Section.Id, returnUrl = Request.Url.PathAndQuery }));

            return result;
        }
    }
}
